package cn.minimal;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Random;

public class TankGameJFrame extends JFrame {
    MyJPanel tankPanel;
    JPanel jPanelFirst, jPanelCenter;
    JMenuBar jMenuBar1;
    JMenuItem jMenuItemStart, jMenuItemExit, jMenuItemSave;
    JSeparator jSeparator1, jSeparator2;
    JMenu jMenuHelp, jMenuSet, jMenuGame;
    CardLayout cardLayout;
    Label label;
    public static int dead_times = 0;
    public static int enemy_dead_times = 0;
    public static Tank lYTank1 = new Tank(10, 10, 0, 0);
    public static final int E_NUM = 10;
    public static eTank[] eTanks = new eTank[E_NUM];
    Random generator = new Random();
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                TankGameJFrame inst = new TankGameJFrame();
                inst.setLocationRelativeTo(null);
                inst.setVisible(true);
            }
        });
    }
    public TankGameJFrame() {
        super();
        initGUI();
    }
    private void initGUI() {
        jPanelCenter = new JPanel();
        cardLayout = new CardLayout();
        jPanelCenter.setLayout(cardLayout);
        getContentPane().add(jPanelCenter, BorderLayout.CENTER);

        jPanelFirst = new JPanel();
        jPanelFirst.setLayout(null);
        jPanelFirst.setPreferredSize(new Dimension(800, 600));
        jPanelFirst.setBackground(new Color(120, 100, 156));
        label = new Label("Stage: 1");
        label.setBounds(100, 50, 120, 30);
        label.setFont(new Font("stfangsong", 1, 20));
        label.setForeground(new Color(255, 255, 255));
        jPanelFirst.add(label);
        jPanelCenter.add("first", jPanelFirst);
        cardLayout.show(jPanelCenter, "first");

        jMenuBar1 = new JMenuBar();
        setJMenuBar(jMenuBar1);
        jMenuGame = new JMenu();
        jMenuBar1.add(jMenuGame);
        jMenuGame.setText("游戏(G)");
        jMenuItemStart = new JMenuItem();
        jMenuGame.add(jMenuItemStart);
        jMenuItemStart.setText("开始");
        jSeparator1 = new JSeparator();
        jMenuGame.add(jSeparator1);
        jMenuItemStart.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                for(int i = 0; i < E_NUM; i++) {
                    eTanks[i] = new eTank(200+i*50, 10, 1, 3);
                    Thread t = new Thread(eTanks[i]);
                    t.start();
                }
                tankPanel = new MyJPanel();
                jPanelCenter.add("game", tankPanel);
                cardLayout.show(jPanelCenter, "game");
                Thread t = new Thread(tankPanel);
                t.start();
                addKeyListener(tankPanel);
            }
        });
        jMenuItemSave = new JMenuItem();
        jMenuGame.add(jMenuItemSave);
        jMenuItemSave.setText("保存");
        jSeparator2 = new JSeparator();
        jMenuGame.add(jSeparator2);
        jMenuItemExit = new JMenuItem();
        jMenuGame.add(jMenuItemExit);
        jMenuItemExit.setText("退出");
        jMenuItemExit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                System.exit( 0 );
            }
        });
        jMenuSet = new JMenu();
        jMenuBar1.add(jMenuSet);
        jMenuSet.setText("设置(T)");
        jMenuHelp = new JMenu();
        jMenuBar1.add(jMenuHelp);
        jMenuHelp.setText("帮助(P)");






        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //pack();
        setSize(800, 600);
    }
}
